package com.mentalhealthplatform.teacherV2.repository;

import com.mentalhealthplatform.appModels.Assessment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Repository
public interface AssessmentRepositoryV2 extends JpaRepository<Assessment, Long> {
    // 通过ID查找Assessment，并同时获取相关的学生信息
    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.id = :id")
    Optional<Assessment> findByIdWithStudent(@Param("id") Long id);

    // 获取所有Assessment，并同时获取相关的学生信息
    @Query("SELECT a FROM Assessment a JOIN FETCH a.student")
    List<Assessment> findAllWithStudent();

    // 通过学生学号查找Assessment，并同时获取相关的学生信息
    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.student.number = :sno")
    List<Assessment> findByStudent_Number(@Param("sno") String sno);

    // 通过评价查找Assessment，并同时获取相关的学生信息
    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.evaluation LIKE %:evaluation%")
    List<Assessment> findByEvaluationContaining(@Param("evaluation") String evaluation);

    // 通过学生ID查找Assessment，并同时获取相关的学生信息
    @Query("SELECT a FROM Assessment a WHERE a.student.id = :studentId ORDER BY a.submittedTime")
    List<Assessment> findByStudentId(@Param("studentId") UUID studentId);
}